package com.example.plugin_native.entity

import com.google.gson.Gson
import com.map.interfaces.Point
import com.map.utils.TransferOfAxesUtil

/*
{
  "color": "#19C919",
  "describe": "种植中",
  "id": 86,
  "plotArea": 100.0,
  "plotCode": 133,
  "plotName": "聚峰谷油橄榄",
  "plotPosition": "[\"30.765537891995464,104.52821326639082\",\"30.765482186157328,104.52809554713527\",\"30.765279583093506,104.52827710108113\",\"30.76521454940779,104.5282770981081\",\"30.765030101246257,104.52840578059556\",\"30.764918516527157,104.52859831387087\",\"30.764677808551166,104.52881179214314\",\"30.764585262561347,104.52899435211683\",\"30.764529652220382,104.52920784106792\",\"30.76441780781321,104.52949714878703\",\"30.76441745834732,104.52962584381645\",\"30.764574220290495,104.52974357241573\",\"30.764777095572228,104.52982838125482\",\"30.764601626704643,104.52996804354719\",\"30.764453056313773,104.53015060660512\",\"30.76446160026565,104.53032120586788\",\"30.764535003821067,104.53055665692882\",\"30.764562556484062,104.53072825663388\",\"30.764496946469965,104.530942752848\",\"30.76434961334986,104.53103852292855\",\"30.764275575041545,104.53103851954879\",\"30.763943775411857,104.53089982765019\",\"30.76378683889266,104.53084594620877\",\"30.763547283996388,104.53100656067241\",\"30.76336175764732,104.53116717832664\",\"30.763131323456967,104.53128489424867\",\"30.763103052724023,104.5313806706898\",\"30.76318540799099,104.53163807839049\",\"30.763258988680168,104.53180968542546\",\"30.763488539277063,104.53202320397887\",\"30.7647613701359,104.53195841133133\",\"30.76536252110279,104.53164316620979\",\"30.76568752990116,104.5317030426996\",\"30.7658107474516,104.53127104898326\",\"30.765437897147724,104.53077019866892\",\"30.765462538608524,104.53016561748976\",\"30.765598245747373,104.52956105136364\",\"30.765664470801426,104.52912309475639\",\"30.76558333045137,104.52842675560944\"]",
  "plotType": "果园",
  "state": 1
}
 */
data class PlotInfoData(
    val color: String,
    val describe: String,
    val id: Int,
    val plotArea: Double,
    val plotCode: Int,
    val plotName: String,
    val plotPosition: String,
    val plotType: String,
    val state: Int
) {
    val points: List<Point>
        get() {
            val list = Gson().fromJson(plotPosition, List::class.java)
            return mutableListOf<Point>().apply {
                list.forEach {
                    val position: List<String> = (it as String).split(",")

                    val pointList = TransferOfAxesUtil.gcj02ToWgs84(
                        position[1].toDouble(),
                        position[0].toDouble()
                    )

                    val point = Point(lng = pointList[0], lat = pointList[1])

                    add(point)
                }
            }
        }
}